package artid.com.arttogo.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.SystemMessageParser;
import artid.com.arttogo.utils.VeDate;


/**
 * 
*    
* 项目名称：ArtworkArt   
* 类名称：SystemMessageAdapter   
* 类描述：系统消息适配器   
* 创建人：耿卫斌   
* 创建时间：2016-6-14 上午10:25:41   
*
 */
public class SystemMessageAdapter extends BaseAdapter {
	private Context mContext;
	private List<SystemMessageParser> list;
	
	public SystemMessageAdapter(Context mContext, List<SystemMessageParser> list) {
		super();
		this.mContext = mContext;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void notifyData(List<SystemMessageParser> list){
		this.list=list;
		notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = LayoutInflater.from(mContext).inflate(R.layout.item_systemmessage, null);
			holder.content=(TextView) v.findViewById(R.id.item_SystemMessageContent);
			holder.time=(TextView) v.findViewById(R.id.item_SystemMessageTiem);
			holder.read=(TextView) v.findViewById(R.id.item_SystemMessageRead);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		holder.content.setText(list.get(position).getTitle());
		holder.time.setText(VeDate.formatUnixTime(list.get(position).getCreattime()));
		if("0".equals(list.get(position).getRead())){
			//已读
			holder.read.setText("已读");
			holder.read.setTextColor(Color.parseColor("#e2e2e2"));
		}else if("1".equals(list.get(position).getRead())){
			//未读
			holder.read.setText("未读");
			holder.read.setTextColor(Color.parseColor("#E81010"));
		}
		return v;
	}
	class ViewHolder {
		TextView content,time,read;
	}

}
